package com.aggregate.pay.xinfu.support.client;

import com.aggregate.pay.xinfu.support.Client;
import com.aggregate.pay.xinfu.support.Merch;
import com.aggregate.pay.xinfu.support.utils.MD5;

/**
 * 交易查询接口
 * @author Moyq5
 * @date 2018年8月31日
 */
public class PayNotify implements Client<String, Boolean> {
	
	private Merch merch;
	
	public PayNotify(Merch merch) {
		this.merch = merch;
	}

	@Override
	public Boolean execute(String data) {
		// [json]&[sign]
		String json = data.split("&")[0];
		
		String signSrc = json + merch.key();
		log.debug("响应签名内容：{}", signSrc);
		
		String sign = MD5.MD5Encode(signSrc).toLowerCase();
		log.debug("响应签名结果：{}", sign);
		
		if (!sign.equals(data.split("&")[1])) {
			log.warn("验签失败");
			return false;
		}
		return true;
	}

}
